<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="checkbox" class="isAll" v-model="isAll">全选
        <button @click="isAll = !isAll">反选</button>
        <br>
        <ul>
            <li v-for="(item, index) in list" :key="index">
                <input type="checkbox" :value="item" v-model="item.isChecked">{{item.name}}
            </li>
        </ul>
    </div>

    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                list: [
                    {id:1, name:'孙悟空', isChecked:false},
                    {id:2, name:'猪八戒', isChecked:false},
                    {id:3, name:'沙悟净', isChecked:false},
                ]
            },
            computed: {
                isAll: {
                    get () {
                        return this.list.every(item => item.isChecked)
                    },
                    set (newValue) {
                        this.list.forEach(item => item.isChecked = newValue)
                    }
                }
            }
        })

    </script>
    
</body>
</html>